package com.financing.platform.dao.impl;

import java.sql.SQLException;
import java.util.Collections;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.financing.platform.dao.INewsDao;
import com.financing.platform.dto.NewsDTO;
import com.financing.platform.util.SqlName;


@Repository("newsDaoImpl")
public class NewsDaoImpl extends BaseDaoImpl implements INewsDao {

	public int addNews(NewsDTO newsDTO) throws SQLException {
		return (Integer) this.sqlMapClient.insert(SqlName.addNews,newsDTO);
	}

	@SuppressWarnings("unchecked")
	public List<NewsDTO> queryNewsList(NewsDTO newsDTO) {
		try {
			return this.sqlMapClient.queryForList(SqlName.newsList,newsDTO);
		} catch (SQLException e) {
			log.error("query news list error",e);
			return Collections.emptyList();
		}
	}

	public int deleteNews(NewsDTO newsDTO) throws SQLException {
		return this.sqlMapClient.delete(SqlName.newsDelete, newsDTO);
	}

	public int updateNews(NewsDTO newsDTO) throws SQLException {
		return this.sqlMapClient.update(SqlName.updateNews,newsDTO);
	}

	@Override
	public int queryNewsListCount(NewsDTO newsDTO) throws SQLException {
		return (Integer) this.sqlMapClient.queryForObject(SqlName.newsListCount,newsDTO);
	}
}
